<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title></title>
</head>
<body>
<!--弹窗：收入编辑-->
<div th:fragment="budgetincomeEdit" class="modal inmodal fade" id="budgetincomeEdit_Modal"
     tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title" id="budgetincomeEdit_modalTitle">编辑收入信息</h4>
                <p id="budgetincomeEdit_modalDesc" class="font-bold text-danger"></p>
            </div>
            <div class="modal-body">
                <form id="budgetincomeEdit_Form">
                    <input id="budgetincomeEdit_id" name="id" type="hidden"/>
                    <div class="row">
                        <div class="col-md-12">
                            <label for="budgetincomeEdit_busiType">业务类型</label>
                            <input class="form-control" id="budgetincomeEdit_busiType"
                                   name="busiType"/>
                        </div>
                        <div class="col-md-12">
                            <label for="budgetincomeEdit_transDate">交易日期</label>
                            <input id="budgetincomeEdit_transDate"
                                   name="transDate"
                                   class="form-control datetimepicker-input"
                                   data-toggle="datetimepicker"
                                   data-target="#budgetincomeEdit_transDate"/>
                        </div>
                        <div class="col-md-12">
                            <label for="budgetincomeEdit_tradeAmount">交易金额</label>
                            <input class="form-control" id="budgetincomeEdit_tradeAmount"
                                   name="tradeAmount"/>
                        </div>
                        <div class="col-md-12">
                            <label for="budgetincomeEdit_payerBankAccount">付款人开户行号</label>
                            <input class="form-control" id="budgetincomeEdit_payerBankAccount"
                                   name="payerBankAccount"/>
                        </div>
                        <div class="col-md-12">
                            <label for="budgetincomeEdit_payerAccountNo">付款人账号</label>
                            <input class="form-control" id="budgetincomeEdit_payerAccountNo"
                                   name="payerAccountNo"/>
                        </div>
                        <div class="col-md-12">
                            <label for="budgetincomeEdit_payerName">付款人名称</label>
                            <input class="form-control" id="budgetincomeEdit_payerName"
                                   name="payerName"/>
                        </div>
                    </div>
                </form>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="budgetincomeEditObj.submitHandler()">
                    保存
                </button>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {
            $('.datetimepicker-input').datetimepicker({
                format: 'YYYYMMDD'
            });
            budgetincomeEditObj.myForm.validate({
                rules: budgetincomeEditObj.dataRule,
                submitHandler: function (form) {
                    budgetincomeEditObj.dataFormSubmit(form);
                }
            });
        })
        var budgetincomeEditObj = new Object({
            myForm: $('#budgetincomeEdit_Form'),
            myModal: $('#budgetincomeEdit_Modal'),
            dataRule: {
                busiType: {
                    required: true,
                    maxlength: 20
                },
                transDate: {
                    required: true
                },
                tradeAmount: {
                    required: true,
                    number: true,
                    min: 0.01,
                    toDecimal2: true
                }
            },
            init: function (id) {
                budgetincomeEditObj.myForm[0].reset();
                $("input[type='hidden']").val("");
                if (id) {
                    $.myGet({
                        url: `/budget/budgetincome/info/${id}`,
                        success: function (data) {
                            if (data && data.code === 0) {
                                for (let key in data.budgetincome) {
                                    if (budgetincomeEditObj.myForm.find(`[name=${key}]`).length > 0) {
                                        budgetincomeEditObj.myForm.find(`[name=${key}]`).val(data.budgetincome[key])
                                    }
                                }
                            } else {
                                toastr.error(data.msg, '操作失败')
                            }
                        }
                    })
                }
                budgetincomeEditObj.myModal.modal('show');
            },
            submitHandler: function () {
                budgetincomeEditObj.myForm.submit();
            },
            dataFormSubmit: function (form) {
                let _self = this;
                let formVals = $(form).serializeArray();
                let data = {}
                for (let i = 0; i < formVals.length; i++) {
                    data[formVals[i].name] = formVals[i].value;
                }
                $.myPost({
                    url: `/budget/budgetincome/${data.id ? 'update' : 'save'}`,
                    dataType: 'json',
                    data: data,
                    success: function (data) {
                        if (data && data.code == 0) {
                            toastr.success(data.msg, '操作提示')
                            _self.myModal.modal('hide')
                            budgetincomeListObj.refreshDataList();
                        } else {
                            toastr.error(data.msg, '操作失败')
                        }
                    }
                })
            }
        })
    </script>

</div>
</body>
</html>